﻿log("Running Taobao Searcher 2  ...  searchSubItems2.js")

// current position
isIndexPage = function ()
{
    return false;
}
isSearchPage = function ()
{
    return location.href.search("category.htm") != -1
    || location.href.search("search.htm") != -1;
}

// index
getSearchEdit = null;
getSubmitButton = null;
// search methods
priceSetted = null;
getSortMethod = null;
locationSetted = null;

// price 
getItemLowerPriceEdit = null;
getItemHigherPriceEdit = null;
getSubmitPriceButton = null;
// sort by
getSortByDefaultButton = null;
getSortBySalesButton = null;
getSortByPolulartyButton = null;

// location
getLocationButton = null;
// items 
getTops = function getTops()
{
    return document.querySelectorAll(".item");
}
getA = function getA(_top)
{
    return _top.querySelector(".detail a.item-name");
}
parseTop = function parseTop(_top)
{
    var img = _top.querySelector(".photo img");
    var a = _top.querySelector(".detail a.item-name");
    var id = a ? /[?&]id=([^&]*)/.exec(a.href)[1] : null;
    var price = _top.querySelector("span.c-price");
    var shop = document.querySelector("a.slogo-shopname, div.tb-shop-name a, .shop-name a");
    var _location = null;

     return {
        extra: {
            top: _top
        },
        title: a ? fixString(a.textContent) : "",
        id: id ? id : "",
        price: price ? fixPrice(fixString(price.textContent)) : "",
        shop: shop ? fixString(shop.textContent) : "",
        link: a ? a.href : "",
        imgsrc: https2http(img ? ((img.src && img.src) != "" ? img.src : ("http:" + img.getAttribute("data-src"))) : ""),
        location: _location ? fixString(_location.textContent) : ""
    };
}

nextPageButton = function ()
{
    return document.querySelector("#mainsrp-pager > div > div > div > ul > li.item.next > a");
}